#!/bin/bash
# Rust 快速安装脚本（适用于 CentOS 7/8）

echo "================================================"
echo "Rust 环境快速安装脚本"
echo "================================================"
echo ""

# 检查是否已安装
if command -v rustc &> /dev/null; then
    echo "✓ Rust 已安装"
    rustc --version
    cargo --version
    echo ""
    echo "如需重新安装，请先卸载："
    echo "  rustup self uninstall"
    exit 0
fi

echo "开始安装 Rust..."
echo ""

export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
# 下载并安装
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# 加载环境变量
source $HOME/.cargo/env

# 验证安装
echo ""
echo "================================================"
echo "安装完成！"
echo "================================================"
echo ""
rustc --version
cargo --version
echo ""
echo "下一步："
echo "1. 重新加载环境变量（当前终端）："
echo "   source \$HOME/.cargo/env"
echo ""
echo "2. 或者重新打开终端"
echo ""
echo "3. 开始编译 moparse："
echo "   cd /home/apachee/trunk/Crystal/CrystalFlowAnalyzer/modb/moparse-rs"
echo "   ./test_build.sh"
echo ""
